package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.getMchDomesticConfigBean;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.getMchDomesticConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_config;
import com.ymttest.database.model.godmch.mch_configExample;
import com.ymttest.database.sqlwapper.godmch.mch_configWapper;
/**
*查询商户国内主体配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getMchDomesticConfig{
	private static getMchDomesticConfigBean bean;
	private static getMchDomesticConfigCall call;
	
	mch_configWapper configWapper;
	mch_configExample configExample;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询商户国内主体配置"); 
	}

	@Before
	public void caseUp() {
		bean=new getMchDomesticConfigBean();
		call=new getMchDomesticConfigCall();
		
		configWapper=new mch_configWapper();
		configExample=new mch_configExample();
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchDomesticConfig_001() {
		Logger.start(true,"查询商户国内主体配置-验证商户是独立商户-mch_config有数据,但不是微信国内主体、不是国内免税店");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			bean.setMchId(createCall.getmchId());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			
			configExample.createCriteria().andMchIdEqualTo(call.getMchId());
		    mch_config  config=configWapper.selectByExample(configExample).get(0);
		    Logger.verifyEquals(call.getMchId(), config.getMchId(), "验证数据库mch_config中的MchId");
			Logger.verifyEquals(call.getWechatDomestic(), config.getWechatDomestic(), "验证数据库mch_config中的WechatDomestic");
			Logger.verifyEquals(false, config.getWechatDomestic(), "验证数据库mch_config中的WechatDomestic=false");
			Logger.verifyEquals(call.getDutyFreeDomestic(), config.getDutyFreeDomestic(), "验证数据库mch_config中的DutyFreeDomestic");
			Logger.verifyEquals(false, config.getDutyFreeDomestic(), "验证数据库mch_config中的DutyFreeDomestic=false");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchDomesticConfig_001_1() {
		Logger.start(true,"查询商户国内主体配置-验证商户是独立商户-mch_config有数据,但是微信国内主体、是国内免税店");
		try {
//			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
//			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Integer mchId=500961771;
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			
			configExample.createCriteria().andMchIdEqualTo(call.getMchId());
		    mch_config  config=configWapper.selectByExample(configExample).get(0);
		    Logger.verifyEquals(call.getMchId(), config.getMchId(), "验证数据库mch_config中的MchId");
			Logger.verifyEquals(call.getWechatDomestic(), config.getWechatDomestic(), "验证数据库mch_config中的WechatDomestic");
			Logger.verifyEquals(true, config.getWechatDomestic(), "验证数据库mch_config中的WechatDomestic=true");
			Logger.verifyEquals(call.getDutyFreeDomestic(), config.getDutyFreeDomestic(), "验证数据库mch_config中的DutyFreeDomestic");
			Logger.verifyEquals(true, config.getDutyFreeDomestic(), "验证数据库mch_config中的DutyFreeDomestic=true");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchDomesticConfig_001_2() {
		Logger.start(true,"查询商户国内主体配置-验证商户是独立商户代理-mch_config无数据-返回WechatDomestic=false,DutyFreeDomestic=false");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Integer mchId=createCall.getmchId();

			applyAgentCall applyAgentCall=GodmchManageCallService.applyAndapproveAgent(mchId);
			
			bean.setMchId(applyAgentCall.getAgentId());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
		
		    Logger.verifyEquals(call.getMchId(), bean.getMchId(), "验证数据库mch_config中的MchId");
			Logger.verifyEquals(false, call.getWechatDomestic(), "验证数据库mch_config中的WechatDomestic=false");
			Logger.verifyEquals(false, call.getDutyFreeDomestic(), "验证数据库mch_config中的DutyFreeDomestic=false");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchDomesticConfig_002() {
		Logger.start(true,"查询商户国内主体配置-验证商户是平台商户");
		try {
			
			Integer mchId=GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			
		    Logger.verifyEquals(call.getMchId(), bean.getMchId(), "验证数据库mch_config中的MchId");
			Logger.verifyEquals(false, call.getWechatDomestic(), "验证数据库mch_config中的WechatDomestic=false");
			Logger.verifyEquals(false, call.getDutyFreeDomestic(), "验证数据库mch_config中的DutyFreeDomestic=false");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchDomesticConfig_003() {
		Logger.start(true,"查询商户国内主体配置-验证商户Id不存在");
		try {
			
			bean.setMchId(99999);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
		    Logger.verifyEquals(call.getMchId(), bean.getMchId(), "验证数据库mch_config中的MchId");
			Logger.verifyEquals(false, call.getWechatDomestic(), "验证数据库mch_config中的WechatDomestic=false");
			Logger.verifyEquals(false, call.getDutyFreeDomestic(), "验证数据库mch_config中的DutyFreeDomestic=false");
				
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchDomesticConfig_004() {
		Logger.start(true,"查询商户国内主体配置-验证商户Id为空");
		try {
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}